package es.mgil.whoWantsToBeAMillonaire.handlers;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.widget.Button;
import android.widget.Toast;
import es.mgil.whoWantsToBeAMillonaire.R;
import es.mgil.whoWantsToBeAMillonaire.activities.Settings;
import es.mgil.whoWantsToBeAMillonaire.runnables.AddFriendRunnable;

public class AddFriendHandler extends Handler {
	private Context context;

	public AddFriendHandler(Context context) {
		this.context = context;
	}

	@Override
	public void handleMessage(Message msg) {
		switch (msg.what) {
		case AddFriendRunnable.ADD_FRIEND_ERROR_EMPTY:
			// can't add a friend if no user name is specified
			Toast.makeText(context, R.string.settings_addFriend_error_names,
					Toast.LENGTH_LONG).show();
			break;
		case AddFriendRunnable.ADD_FRIEND_ERROR_SERVER:
			// a server exception has been occurred
			Toast.makeText(context, R.string.settings_addFriend_error_server,
					Toast.LENGTH_LONG).show();
			break;
		case AddFriendRunnable.ADD_FRIEND_OK:
			// friend added correctly
			Toast.makeText(context, R.string.settings_addFriend_ok,
					Toast.LENGTH_LONG).show();
			break;
		default:
			break;
		}

		// enable add friend button again
		Button addFriend = (Button) ((Settings) context)
				.findViewById(R.id.settings_button_add_friend);
		addFriend.setEnabled(true);
	}
}